var getCookie = readCookie("user")
if(!getCookie){
	location.href="login.htm"
}
var arr=new Array()
var myFlag=""
var count=0
var num=1
	/**
			 * 分页重要属性(这些可以直接用)
			 * PaginJson.pageIndex:当前页
			 * PaginJson.pageSize:每页数量
			 * PaginJson.dataSize:数据量
			 * */
			//创建分页
			
$(function(){
	initData()
	getCollect()
	myPage()
	getUserInfo()
	
})
function getUserInfo(){
	$.ajax({
		url:"http://localhost:8080/user/login",
		type:"post",
		dataType:"json",
		data:{
			"id":getCookie
			},
		async:false,
		success:function(data){
			
			$("#img1").prop("src","http://localhost:8080/"+data.data.img)
		}
	})
}

function myPage(){
	var page = new Pagin({
		el:"#page",	//绑定分页div
		dataSize:count,	//数据量
		pageSize:6	,//每页数量
		func:function(){
			num=PaginJson.pageIndex
			getCollect()
		}
	})
}
function initData(){
	vm=new Vue({
		el:".Collect",
		data:{
			sinfo:[]
		},
		methods:{
		delete1(id){
			myFlag=id
			 $.DialogByZ.Confirm({Title: "", Content: "是否确定删除",FunL:confirmL,FunR:Immediate})
			
		}	
		}
		
	})
}
 function confirmL(){
			$.DialogByZ.Close();
			delete1(myFlag)
			
   }
   function Immediate(){
   	  $.DialogByZ.Close();
      }
function delete1(id){
	$.ajax({
		url: "http://localhost:8080/collect/delete",
		type: "post",
		data: {
			"uId": getCookie,
			"cId":id
			
		},
		async: false,
		dataType: "json",
		success: function(data) {
			getCollect()
			myPage()
		}
	})
}
function getCollect(){
	$.ajax({
		url: "http://localhost:8080/collect/select",
		type: "get",
		data: {
			"uId": getCookie,
			"pageNum":num,
			"pageSize":"6"
		},
		async: false,
		dataType: "json",
		success: function(data) {
			arr=new Array()
			for(var i=0;i<data.data.list.length;i++){

				getCommodity(data.data.list[i].cId)
			}
			count=data.data.total
		
			vm.$data.sinfo=arr
			
		}
	})
}
function getCommodity(id){
	$.ajax({
		url:"http://localhost:8080/commodity/chooseCommodity",
		data:{"id":id},
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			arr.push(data.data)
		}
	})
	
}